<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title></title>
  </head>
  <body>
    <div id="app">
      <h3>获取对象所有的值：</h3>
      <ul>
        <li v-for="value in myObject">{{ value }}</li>
      </ul>

      <h3>获取对象所有的键和值：</h3>
      <ul>
        <li v-for="(value, key) in myObject">{{ key }}: {{ value }}</li>
      </ul>

      <h3>获取对象所有的键、值以及索引：</h3>
      <ul>
        <li v-for="(value, key, index) in myObject">
          {{ index }}. {{ key }}: {{ value }}
        </li>
      </ul>
    </div>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
      const { createApp, reactive } = Vue;

      // v-for 来遍历一个对象的所有属性。遍历的顺序会基于对该对象调用 Object.keys() 的返回值来决定。
      //    先提取Number类型的key，按升序排列，再提取String类型的key，按定义顺序排列
      //    直接百度object.keys顺序：https://blog.csdn.net/halations/article/details/106622364
      createApp({
        setup() {
          const myObject = reactive({
            title: "How to do lists in Vue",
            author: "Jane Doe",
            publishedAt: "2016-04-10",
          });

          return {
            myObject,
          };
        },
      }).mount("#app");
    </script>
  </body>
</html>
